# Maintainer: @naveen521kk on Github, Naveen M K <naveen@syrusdark.website>

_pyname=gi-docgen
_realname=gi-docgen
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=2021.5
pkgrel=1
pkgdesc='Documentation tool for GObject-based libraries (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url="https://gitlab.gnome.org/GNOME/gi-docgen"
license=('GPL3' 'Apache2.0' 'CC0-1.0')
depends=(
  "${MINGW_PACKAGE_PREFIX}-python-markdown"
  "${MINGW_PACKAGE_PREFIX}-python-markupsafe"
  "${MINGW_PACKAGE_PREFIX}-python-pygments"
  "${MINGW_PACKAGE_PREFIX}-python-jinja"
  "${MINGW_PACKAGE_PREFIX}-python-toml"
  "${MINGW_PACKAGE_PREFIX}-python-typogrify"
)
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-python-setuptools"
)
source=(
  "${_pyname}-${pkgver}.tar.gz::https://pypi.org/packages/source/${_pyname::1}/${_pyname}/${_pyname}-${pkgver}.tar.gz"
)
sha256sums=('80c3d0be60b2080aa0d3f601ced9f4a2930b1e7d9fe6d0a18881033e69bc3eeb')

prepare() {  
  cd "$srcdir"
  rm -rf python-build-${CARCH} | true
  cp -r "${_pyname//_/-}-$pkgver" "python-build-${CARCH}"
  export SETUPTOOLS_SCM_PRETEND_VERSION=${pkgver}
}

build() {
  msg "Python build for ${CARCH}"  
  cd "${srcdir}/python-build-${CARCH}"
  ${MINGW_PREFIX}/bin/python setup.py build
}

package() {
  cd "${srcdir}/python-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build

  install -Dm644 LICENSES/Apache-2.0.txt "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/Apache-2.0.txt"
  install -Dm644 LICENSES/GPL-3.0-or-later.txt "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/GPL-3.0-or-later.txt"

  for _f in "${pkgdir}${MINGW_PREFIX}"/bin/*-script.py; do
    sed -e '1 { s/^#!.*$// }' -i ${_f}
  done
}
